#ifndef __G_TASK_DEQUEUE_H__
#define __G_TASK_DEQUEUE_H__

#include <list>

#include "GTask.h"
#include "GTypes.h"
#include "GSpinMutex.h"
#include "GSemaphore.h"

#define G_TASK_YIELD_MAX_SIZE		4
#define G_TASK_QUEUE_MAX_SIZE		512

namespace GEngine
{

	class GTaskQueue
	{
	typedef GThread::GSpinMutex Mutex;
	typedef std::list<GTask*> TaskListType;
	typedef std::vector<GTaskQueue*> QueueArrType;

	private:
		Mutex			Lock;
		TaskListType	Queue;
		QueueArrType	Victims;

		bool			IsFull() const;
		bool			IsEmpty() const;
		GSize			GetCount() const;

		bool			Supply(GTaskQueue* OtherQueue);
		
	public:
						GTaskQueue();
						~GTaskQueue();

		void			Clear();

		bool			Steal();

		void			AddVictim(GTaskQueue* VictimQueue);

		bool			Push(GTask* Task);
		bool			Pop(OUTPUT GTask** OutTask);

		bool			Create(GTaskQueue** VictimArr, GSize VictimCount);
		void			Release();
	};

}

#endif